package sm.hibernate.type;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.hibernate.HibernateException;

import sm.def.Type;

public class RCTimeType extends AbstractRCPrimitiveType {

	@Override
	public Object deepCopy(Object value) throws HibernateException {
		if (value instanceof Date) {
			Date date = (Date) value;
			return date.clone();
		} else {
			return value;
		}

	}

	@Override
	public boolean isMutable() {
		return true;
	}

	@Override
	public Serializable disassemble(Object value) throws HibernateException {
		return (Serializable) deepCopy(value);
	}

	@Override
	public Object assemble(Serializable cached, Object owner)
			throws HibernateException {
		return deepCopy(cached);
	}

	@Override
	public Object replace(Object original, Object target, Object owner)
			throws HibernateException {
		return deepCopy(original);
	}

	@Override
	public Class returnedClass() {
		return Date.class;
	}

	@Override
	public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
			throws HibernateException, SQLException {
		return nullSafeGet(rs, names, owner, Type.TIME_TYPE);
	}

	@Override
	public void nullSafeSet(PreparedStatement st, Object value, int index)
			throws HibernateException, SQLException {
		nullSafeSet(st, value, index, Type.TIME_TYPE);
	}

}
